define(['app'], function( app ) {
    'use strict';
    app.directive('floatLayer', function (dataFactoryCRM, $q ,$rootScope){
        return {
            restrict : 'EA',
            replace : true,
            transclude : true,
            scope : {
                customerId  : '=customerId',
                showName : '=showName'
            },
            template : '<div">'
                +'<div class="ui left pointing dropdown item">'
                +'<div class="title"  ng-mouseover="showCusInfos($event)" ng-mouseout="hideCusInfos($event)">{{showName}}</div>'
                +'<div class="menu">'
                +'<div class="item clearfix"  style="min-width: 320px;"><img src="dist/images/360_admin.png" alt="" />'
                +'<b>{{showName}}({{customerInfo.customer_code}})</b>'
                +'<a ng-click="openDetail(customer_id)" style="float:right; position:relative; top: 6px">更多</a></div>'
                +'<div class="item">资金量：{{customerInfo.mount}}w &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;累积服务时长：{{servicedDayDetail}}天</div>'
                +'<div class="item"><b>服务中合同：{{contractCountDetail}}</b></div>'
                +'<div ng-show="contractInfoDetail">'
                +'<table style="border:none"><tr ng-repeat="vlist in contractInfoDetail" style="border:none">'
                +'<td style="width:25%;border:none">{{vlist.productname}}</td>'
                +'<td style="border:none">{{vlist.paymount}}元</td>'
                +'<td style="border:none">剩余:{{vlist.remainDays}}天(到期时间：{{vlist.end_time}})</td>'
                +'</tr></table></div>'
                +'<div class="item"><b>投诉次数：{{complainCountDetail}}</b></div>'
                +'<div class="item">'
                +'<div style="width: 390px; color:#666; line-height:1.6; white-space:normal; overflow: hidden;  display: -webkit-box;display: -moz-box;display: box;-webkit-box-orient: vertical;-moz-box-orient: vertical;box-orient: vertical;-webkit-line-clamp: 2;-moz-line-clamp: 2;line-clamp: 2;">备注：{{customerInfo.remark}}</div></div>'
                +'</div>'
                +'</div>',
            link : function(scope, element, attrs) {
                scope.isLoad = false;
                scope.customer_id = 0;
                scope.customerInfo = {};
                scope.customer_id = scope.customerId;
                scope.openDetail = function(val) {
                    if(val){
                        window.open("detail.html#/View360/"+ val);
                    }
                }

                scope.showCusInfos = function(event){
                     if (!scope.isLoad){
                        dataFactoryCRM.getDataByAPI("Customer/getFloatInfos?customer_id="+scope.customer_id)
                            .then(function(data) {
                                scope.customerInfo = data.customerInfo;
                                scope.contractInfoDetail = data.contractInfo;
                                scope.complainCountDetail = data.complainCount;
                                scope.contractCountDetail = data.contractCount;
                                scope.servicedDayDetail = data.servicedDay;
                                scope.isLoad = true;
                        });
                    }
                    $(event.target).css("color","#4183C4");
                    $(event.target).parent().dropdown({on:"hover"});

                }
                scope.hideCusInfos = function(event){
                   $(event.target).css("color","#333");
                }
            }
        }
    });
});
